package com.jy.adscm.hcPlan.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.hcPlan.bean.HcPlanAfterFinalAssemblyExample;
import com.jy.adscm.hcPlan.bean.HcPlanFinalAssembly;
import com.jy.adscm.hcPlan.bean.support.HcPlanFinalAssemblyExampleSupport;
import com.jy.adscm.hcPlan.bean.support.HcPlanFinalSupportBean;
import com.jy.adscm.hcPlan.service.HcPlanFinalAssemblyService;
import com.jy.adscm.hcPlan.service.HcPlanMakePartExampleService;
import com.jy.adscm.hcPlan.service.HcPlanMakePartMaterielExampleService;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.utils.AdscmDateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 耗材总装表 前端控制器
 * </p>
 *
 * @author yyy
 * @since 2018-08-13
 */
@RestController
@RequestMapping("/adscm/hcplan/hcPlanFinalAssembly")
public class HcPlanFinalAssemblyController {


    @Autowired
    HcPlanFinalAssemblyService hcPlanFinalAssemblyService;

    @Autowired
    HcPlanMakePartExampleService hcPlanMakePartExampleService;

    @Autowired
    HcPlanMakePartMaterielExampleService hcPlanMakePartMaterielExampleService;

    /**
     * 查询总装列表
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/queryHcPlanFinalAssemblyList")
    public SimpleCoreResponse queryHcPlanFinalAssemblyList() throws AdscmSystemException{

//        HcPlanFinalSupportBean bean = hcPlanFinalAssemblyService.queryHcPlanFinalAssemblyList();

        return new SimpleCoreResponse("200","查询成功",hcPlanFinalAssemblyService.queryHcPlanFinalAssemblyList());

    }

    /**
     * 根据已有销售任务，生成总装数据
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadFinalAssembly")
    public SimpleCoreResponse loadFinalAssembly(String date) throws AdscmSystemException{

        hcPlanFinalAssemblyService.loadFinalAssembly(date);

        return new SimpleCoreResponse("200","生成成功",null);

    }
    /**
     * 直接修改总装的起止时间
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/editFinalAssemblyDate/{id}/{ass_start_date}/{ass_end_date}")
    public SimpleCoreResponse editFinalAssemblyDate(@PathVariable Long id,@PathVariable String ass_start_date,@PathVariable String ass_end_date) throws AdscmSystemException{
        HcPlanFinalAssembly finalAssembly = new HcPlanFinalAssembly();
        finalAssembly.setId(id);

        if (AdscmBaseUtils.getInstance().isNotEmpty(ass_start_date,null)){

            finalAssembly.setAss_start_date(AdscmDateUtils.parseDate(ass_start_date));
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(ass_end_date,null)){

            finalAssembly.setAss_end_date(AdscmDateUtils.parseDate(ass_end_date));
        }
        finalAssembly.setFinal_ass_status(1);//修改状态
        hcPlanFinalAssemblyService.editFinalAssemblyDate(finalAssembly);
        System.out.println(ass_end_date);

        //装配单批次零件制造的数据
        hcPlanMakePartExampleService.loadHcPartExampleByAssemblyId_new1(id);

        //装配单批次物料采购数据
        hcPlanMakePartMaterielExampleService.loadHcPartMaterielExampleByAssemblyId(id);

        return new SimpleCoreResponse("200","修改成功",null);

    }

    /**
     * 修改某一批次总装后面环节的时间
     * @param list
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/editAfterFinalAssemblyExample")
    public SimpleCoreResponse editAfterFinalAssemblyExample(List<HcPlanAfterFinalAssemblyExample> list) throws AdscmSystemException{

        hcPlanFinalAssemblyService.editAfterFinalAssemblyExample(list);


        return new SimpleCoreResponse("200","修改成功",null);

    }
    /**
     * 提交总装任务
     * @param id ：总装ID
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/submitFinalAssemblyTask/{id}")
    public SimpleCoreResponse submitFinalAssemblyTask(@PathVariable Long id) throws AdscmSystemException{

        hcPlanFinalAssemblyService.submitFinalAssemblyTask(id);

        //装配单批次零件制造的数据
        hcPlanMakePartExampleService.loadHcPartExampleByAssemblyId_new1(id);

        //装配单批次物料采购数据
        hcPlanMakePartMaterielExampleService.loadHcPartMaterielExampleByAssemblyId(id);

        return new SimpleCoreResponse("200","提交任务成功",null);

    }
    /**
     * 获取某一个总装计划详情
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getFinalAssemblyDetail/{sale_task_flow_num}/{goods_id}")
    public SimpleCoreResponse getFinalAssemblyDetail(@PathVariable String sale_task_flow_num,@PathVariable String goods_id) throws AdscmSystemException{

        return new SimpleCoreResponse("200","查询成功",hcPlanFinalAssemblyService.getFinalAssemblyDetail(sale_task_flow_num,goods_id));

    }

}



